import { IBiz } from './biz'
import { IPagination } from './pagination'
import { IQueryParams } from './queryParams'
import { propertyMap } from '@shared/decorators/property-map'
import { EUserType, EUserStatus } from '@shared/enums'
import { IMenu } from './role'
import { AuditConfig } from './acquirer'

/* 查询请求参数 */
export interface IUserQueryParams extends IQueryParams, IBiz {
  username?: string,
  nickName?: string,
  email?: string,
  insCode?: string,
  agentCode?: string,
  userRole?: string,
  intMerCode?: string,
  intStoreCode?: string
}

/* 机构下查询用户请求参数 */
export interface IAcquirerUserQueryParams extends IQueryParams, IBiz {
  insCode: string,
}

export class UserRole {
  id: string
  roleDesc: string
  roleId: number
  roleName: string
  roleType: number
  insCodes: string[]
  creatorId?: string
  creatorName?: string
}

export interface IAllLevelRoles {
  insRoles: UserRole[],
  agentRoles: UserRole[],
  merchantRoles: UserRole[],
  storeRoles: UserRole[],
}

/* 新增请求数据 */
export class UserReq {
  username: string
  nickName: string
  email: string
  password: string
  roleID?: string
  roleIDs?: string[]
}

export class ILoginForm {
  username: string
  password: string
}

/* 查询返回数据 */
export class User {
  no: number
  id: string
  insCode: string
  insName: string
  insNameEN: string
  agentCode: string
  agentName: string
  agentNameEN: string
  intMerCode: string
  merNum: string
  merName: string
  merNameEN: string
  storeName: string
  storeNum: string
  storeNameEN: string
  intStoreCode: string
  userName: string
  password: string
  phoneNum: string
  mail: string
  nickName: string
  areaCode: string
  userType: EUserType
  auditConfigs?: AuditConfig[]
  auditPermissions?: number[] // 机构用户配置审权限

  createdAt: string
  updatedAt: string
  roleIDs: number[]
  roleID?: number
  // New user key
  username: string
  email: string
  roles: UserRole[]
  version: number
  status: EUserStatus
  passwordCF?: string
  data?: IMenu[]
  bizLevelCode?: string
}

export interface IUserPagination extends IPagination {
  data: User[]
}

// Change password params
export interface IChangePassword {
  passwordOld?: string
  passwordNew: string
}

// Update user detail
export interface IUpdateUser {
  nickName: string
  email: string
  roleIDs: number[]
  status: string
  version: number
}

// Create user
export interface ICreateUserForm {
  userType: string
  insCode: string
  agentCode: string
  intMerCode: string
  intStoreCode: string
  username: string
  nickName: string
  email: string
  password: string
  roleIDs: number[]
  auditPermissions?: number[] // 机构用户配置审权限
}

export interface ICreateUser {
  users: ICreateUserForm[]
}

